package com.wyx.jdbc.datasource;

import org.junit.jupiter.api.Test;

import java.sql.*;

/**
 * @author 王艺锡
 * @version 1.0
 */
public class test_DruidUtils {


    @Test
    public void select(){
        //测试查询语句的使用
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;

        try {
            connection = JDBCUtils_Druid.getConnection();
            String sql = "select * from actor";
            preparedStatement = connection.prepareStatement(sql);
            resultSet = preparedStatement.executeQuery();
            while (resultSet.next()){
                int id = resultSet.getInt("id");
                String name = resultSet.getString("name");
                String sex = resultSet.getString("sex");
                Date birthday = resultSet.getDate("borndate");
                String phone = resultSet.getString("phone");
                System.out.println(id + "\t" + name + "\t" + sex + "\t" + birthday + "\t" + phone);
            }


        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            JDBCUtils_Druid.close(resultSet,preparedStatement,connection);
        }

    }
}
